<template>
  <div>
    <video ref="videoPlayer" class="video-js vjs-default-skin"></video>
  </div>
</template>

<script>
import videojs from 'video.js';
import 'video.js/dist/video-js.css';
import 'videojs-contrib-hls';

export default {
  name: 'VideoPlayer',
  props: {
    m3u8Url: {
      type: String,
      required: true
    }
  },
  mounted() {
    this.player = videojs(this.$refs.videoPlayer, this.videoOptions, function onPlayerReady() {
      console.log('Player is ready');
    });
  },
  beforeDestroy() {
    if (this.player) {
      this.player.dispose();
    }
  },
  data() {
    return {
      player: null,
      videoOptions: {
        autoplay: true,
        controls: true,
        preload: 'auto',
        fluid: true,
        sources: [{
          src: this.m3u8Url,
          type: 'application/x-mpegURL'
        }]
      }
    };
  }
};
</script>

<style>
.video-js .vjs-tech {
  width: 100%;
  height: auto;
}
</style>
